<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>好友选择器测试</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 400px;
            margin: 0 auto;
            padding: 20px;
        }
        .test-container {
            border: 1px solid #ddd;
            padding: 20px;
            border-radius: 8px;
            margin: 20px 0;
        }
        .friend-selector {
            margin: 10px 0;
        }
        .select-friend-btn {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            background: #fff;
            cursor: pointer;
        }
        .friend-list-modal {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0, 0, 0, 0.5);
            z-index: 1000;
            display: none;
            flex-direction: column;
        }
        .modal-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 16px;
            background: #fff;
            border-bottom: 1px solid #eee;
        }
        .close-btn {
            width: 32px;
            height: 32px;
            border: none;
            background: #f5f5f5;
            border-radius: 50%;
            font-size: 20px;
            color: #666;
            cursor: pointer;
        }
        .search-container {
            padding: 16px;
            background: #fff;
            border-bottom: 1px solid #eee;
        }
        .search-input {
            width: 100%;
            padding: 10px 12px;
            border: 1px solid #ddd;
            border-radius: 6px;
            font-size: 14px;
        }
        .friend-list {
            flex: 1;
            background: #fff;
            overflow-y: auto;
        }
        .friend-item {
            display: flex;
            align-items: center;
            padding: 12px 16px;
            border-bottom: 1px solid #f0f0f0;
            cursor: pointer;
        }
        .friend-item:hover {
            background: #f5f5f5;
        }
        .friend-avatar {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            margin-right: 12px;
            background: #ddd;
        }
        .friend-info {
            flex: 1;
        }
        .friend-name {
            font-weight: 500;
            margin-bottom: 2px;
        }
        .friend-status {
            font-size: 12px;
            color: #999;
        }
        .selected-indicator {
            color: #4CAF50;
            font-size: 18px;
            font-weight: bold;
        }
        .current-user-display {
            padding: 12px 16px;
            background: #e8f4fd;
            border: 1px solid #b3d9ff;
            border-radius: 8px;
            text-align: center;
            color: #1976d2;
            font-weight: 500;
        }
    </style>
</head>
<body>
    <h1>好友选择器测试</h1>
    
    <div class="test-container">
        <h3>测试1: 普通好友选择</h3>
        <div class="friend-selector">
            <button class="select-friend-btn" onclick="showFriendList()">
                <span id="selected-friend-text">选择好友</span>
            </button>
        </div>
    </div>
    
    <div class="test-container">
        <h3>测试2: 当前用户显示</h3>
        <div class="current-user-display">
            当前用户 (12345)
        </div>
    </div>
    
    <div class="test-container">
        <h3>测试3: 已选择好友显示</h3>
        <div class="friend-selector">
            <button class="select-friend-btn" onclick="showFriendList()">
                <span>张三</span>
            </button>
        </div>
    </div>

    <!-- 好友列表弹窗 -->
    <div id="friend-list-modal" class="friend-list-modal">
        <div class="modal-header">
            <h3>选择好友</h3>
            <button class="close-btn" onclick="closeModal()">×</button>
        </div>
        
        <div class="search-container">
            <input class="search-input" placeholder="搜索好友..." oninput="onSearch(this.value)">
        </div>
        
        <div class="friend-list" id="friend-list">
            <!-- 模拟好友数据 -->
            <div class="friend-item" onclick="selectFriend('李四', 1001)">
                <div class="friend-avatar"></div>
                <div class="friend-info">
                    <div class="friend-name">李四</div>
                    <div class="friend-status">在线</div>
                </div>
            </div>
            <div class="friend-item" onclick="selectFriend('王五', 1002)">
                <div class="friend-avatar"></div>
                <div class="friend-info">
                    <div class="friend-name">王五</div>
                    <div class="friend-status">离线</div>
                </div>
            </div>
            <div class="friend-item" onclick="selectFriend('赵六', 1003)">
                <div class="friend-avatar"></div>
                <div class="friend-info">
                    <div class="friend-name">赵六</div>
                    <div class="friend-status">在线</div>
                </div>
            </div>
        </div>
    </div>

    <script>
        function showFriendList() {
            document.getElementById('friend-list-modal').style.display = 'flex';
        }
        
        function closeModal() {
            document.getElementById('friend-list-modal').style.display = 'none';
        }
        
        function selectFriend(name, id) {
            document.getElementById('selected-friend-text').textContent = name;
            closeModal();
            console.log('选择了好友:', name, 'ID:', id);
        }
        
        function onSearch(keyword) {
            const friends = document.querySelectorAll('.friend-item');
            friends.forEach(friend => {
                const name = friend.querySelector('.friend-name').textContent;
                if (name.toLowerCase().includes(keyword.toLowerCase())) {
                    friend.style.display = 'flex';
                } else {
                    friend.style.display = 'none';
                }
            });
        }
        
        // 点击模态框外部关闭
        document.getElementById('friend-list-modal').addEventListener('click', function(e) {
            if (e.target === this) {
                closeModal();
            }
        });
    </script>
</body>
</html>
